package logic

import (
	"context"
	"gorm.io/gorm"
	"taobao-merchandise/models"

	"taobao-merchandise/taobaorpc/internal/svc"
	"taobao-merchandise/taobaorpc/taobaorpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type ProductAddLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewProductAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ProductAddLogic {
	return &ProductAddLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *ProductAddLogic) ProductAdd(in *taobaorpc.ProductAddRequest) (*taobaorpc.ProductAddResponse, error) {
	// todo: add your logic here and delete this line
	product := models.Product{
		Model:  gorm.Model{},
		Title:  in.Title,
		UserId: in.UserId,
		Price:  float64(in.Price),
		Stock:  in.Stock,
		Image:  in.Image,
	}
	models.DB.Create(&product)
	return &taobaorpc.ProductAddResponse{
		ProductId: int64(product.ID),
	}, nil
}
